package com.bosssoft.trainee.nontax.controller;


import com.bosssoft.trainee.nontax.entity.po.Words;
import com.bosssoft.trainee.nontax.common.Result;
import com.bosssoft.trainee.nontax.service.IWordsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author MaYunFei
 * @ProjectName springboot-vue-RBAC
 * @Description TODO
 * @time 2022/6/3 15:23
 */

@RestController
@RequestMapping("/words")
public class WordsController extends BaseController{

    @Resource
    private IWordsService wordsService;

    @GetMapping("/all")
    public Result<?> findAll(){
        return Result.success(wordsService.list());
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {
        boolean b = wordsService.removeById(id);
        return b ? Result.success("删除成功！") : Result.error("601","对象不存在！");
    }

    @PostMapping
    public Result<?> save(@RequestBody Words words) {
        wordsService.save(words);
        return Result.success();
    }

    @GetMapping("/page")
    public Result<?> findPage(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                              @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return wordsService.findPage(pageNum, pageSize);
    }

}
